package com.kjc.demo.basic.algorithmtest;

public class ShellSort {
	public void sort(int[] arr) {
		for(int gap = arr.length/2; gap>=0; gap= gap/2) {
			for(int i=gap; i < arr.length-1 ;i++) {
				int j = i;
				while(j-gap >= 0 && arr[j] < arr[j-gap]) {
					swap(arr,j,j-gap);
					j=j-gap;
				}
			}
		}
	}
	
	public void swap(int[] arr, int i , int j) {
		int temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
	}
}
